package com.cndw.kungfu.model.sys;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cndw.commons.util.BlankUtils;
import com.cndw.kungfu.core.CacheDataBase;
import com.cndw.kungfu.domain.DataInfoSys;
import com.cndw.kungfu.ext.SerializeProcesser;

@Service
public class SysServer {
	@Autowired
	private SysManger sysManger;
	@Autowired
	private LogManager logManager;

	public void debugMysql() {
		sysManger.debugMysql();
	}

	public void clearLogByDate(){
		logManager.clearLog30();
	}
	
	public CacheDataBase initCacheData(String sysKey){
		DataInfoSys data = sysManger.loadCacheDataDb(sysKey);
		if (!BlankUtils.isBlank(data)) {
			String cacheDataString = data.getSysData();
			if (cacheDataString!=null) {
				try {
					CacheDataBase cacheData = (CacheDataBase) SerializeProcesser.readObject(cacheDataString);
					cacheData.setSyncDBTime(data.getSyncDBTime());
					return cacheData;
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			
		}		
		return null;
	}

}
